package thinkinjava4.ch13_strings;

import java.util.Scanner;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ThreatAnalyzer {
    static String threatData = "58.27.82.161@15/01/2018\n" +
            "204.45.234.40@15/01/2018\n" +
            "58.27.82.161@15/01/2018\n" +
            "58.27.82.161@15/01/2018\n" +
            "58.27.82.161@15/01/2018\n" +
            "[Next log section with differernt data format]";

    public static void main(String[] args) {
        Scanner scanner = new Scanner(threatData);
        String pattern = "(\\d+[.]\\d+[.]\\d+[.]\\d+)@(\\d{2}/\\d{2}/\\d{4})";
        while (scanner.hasNext(pattern)) {
            scanner.next(pattern);
            MatchResult match = scanner.match();
            String ip = match.group(1);
            String date = match.group(2);
            System.out.format("Threat on %s from %s\n", date, ip);
        }
        System.out.println(" http://192.168.0.119:8081/home/GetHomeAdImgList.do"
                .replaceAll("/.+|\\D+/|:\\d+", ""));
    }
}
